home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / DSHJ2 / DBASE.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  63.7 KB  |  2,583 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /*    DBASE.C                                */
  4. /*                                    */
  5. /*    This file contains the data structures and the associated       */
  6. /*     routines for the DESKSET II page layout program            */
  7. /*                                    */
  8. /*    ROUTINES:                            */
  9. /*                                    */
  10. /*    init_structs()        - Initialize pointers            */
  11. /*    create_article()     - Add article structure to list     */
  12. /*    add_to_article()    - Add region to article list        */
  13. /*    getf_aregion()        - Get current articles first region     */
  14. /*    getn_aregion()        - Get current articles next regions     */
  15. /*    update_article()    - Set cur. arts. fname and buf_start    */
  16. /*    get_arttxt()        - Get text ptr of current article      */
  17. /*    get_artfname()        - Get file name of article        */
  18. /*     put_txtptr()        - Set text ptr of current region    */
  19. /*    put_txtattr()        - Set attributes of current region    */
  20. /*    get_txtptr()        - Get text ptr of current region        */
  21. /*    get_txtattr()        - Get text attributes of current region */
  22. /*     get_grattr()        - Get graphic attributes of curr region */
  23. /*    put_grattr()        - Put graphic attributes of curr region */
  24. /*    add_page()        - Add page structure to page list       */
  25. /*    add_region()        - Add a region to the current page      */
  26. /*    valid_page()        - Set curpage to requested page,        */
  27. /*                  return 0L if this page doesn't exist  */
  28. /*    create_region()        - Call add_region for requested page    */
  29. /*                  Call add_page if necessary        */
  30. /*    get_fregion()        - Get first region of requested page    */
  31. /*    get_nregion()        - Get subsequent regions after that     */
  32. /*    open_region()        - Make current region = requested one   */
  33. /*    calc_newbounds()    - Calc bounding rectangle of region     */
  34. /*    add_prim()        - Add a primitive to current region     */
  35. /*    put_poly()        - Put a polygon into the primitive list */
  36. /*    put_ellipse()        - Put an ellipse into "   "   "         */
  37. /*    put_image()        - Put an picture into "   "   "        */
  38. /*    getpts()        - Put current primitive's points into   */
  39. /*                  the global ptsarray            */
  40. /*    get_fprimitive()    - Get the current regions first prim.   */
  41. /*    get_nprimitive()    - Get the regions next primitives    */
  42. /*    prev_region()        - Return the region right before the    */
  43. /*                  requested one in the page list        */
  44. /*    find_region()        - Given region at a given x and y     */
  45. /*    prev_prim()        - Get primitive before requested one    */
  46. /*    del_pts()        - Delete all blocks of a primitive      */
  47. /*    delete_primitive()    - Delete current primitive        */
  48. /*    delete_region()        - Delete current region            */
  49. /*     unlink_region()        - Unlink region from it's article     */
  50. /*    get_fpage()        - Return first page of our page list    */
  51. /*    get_npage()        - Return next pages of our page list    */
  52. /*    prev_page()        - Get page previous to requested one    */
  53. /*    delete_page()        - Delete current page            */
  54. /*    getf_article()        - Get first article in article list     */
  55. /*    getn_article()        - Get next articles in list        */
  56. /*    prev_art()        - Get previous article in article list  */
  57. /*    prev_aregion()        - Get prev region in article list       */
  58. /*    delete_article()    - Delete current article         */
  59. /*    getpagenum()        - Get page number of current page     */
  60. /*    get_regart()        - Return register's article pointer     */
  61. /*    open_article()        - Make given article the current one    */
  62. /*    chk_repel()        - Check graphics repelling        */
  63. /*    get_curreg()        - return curregion and type        */
  64. /*    set_repbuff()        - Set gr. regions repel buffer          */
  65. /*                                    */
  66. /************************************************************************/
  67.  
  68. #include "dbase.h"
  69. #include "alert.h"
  70. #include <osbind.h>
  71. #include "deskset2.h"
  72.  
  73. ARTICLE *artptr;
  74. ARTICLE *curart;
  75. ARTICLE *arthd;
  76.  
  77. PAGE    *pagehd;
  78. PAGE    *pageptr;
  79. PAGE    *curpage;        /* Current page pointer             */
  80. PAGE    *clippage;
  81.  
  82. REGION    *curregion;        /* Current region working region     */
  83. REGION  *sfregion;
  84.  
  85. PRIMITIVE *curprim;
  86.  
  87. PTSBLK    *curblk;
  88.  
  89. SCANINFO *sfscan;
  90.  
  91. #define NULLPTR     0x0L
  92. #define DSPOLY       0
  93. #define DSELLIPSE     1
  94. #define DSPICTURE    2
  95. #define DSLINE        3
  96. #define DSRBOX        4
  97.  
  98. #define NUMGRATTRS    9        /* Number of text attributes    */
  99.  
  100. int    ptsarray[256];            /* Global array where points are */
  101.                     /* Passed between data base and  */
  102.                     /* main module             */
  103.  
  104. extern REGION   *insert_regptr;
  105. extern unsigned char *buf_start;
  106. extern unsigned char *buf_end;
  107. extern unsigned char *free_start;
  108. extern unsigned char *current_char;
  109. extern char *get_lcmem();
  110.  
  111. extern int hpage_size;
  112. extern int curr_page;
  113.  
  114. extern unsigned long scanptr;
  115. extern int alerted;
  116. extern int alt_offset;
  117. extern int view_size;
  118.  
  119.  
  120.  
  121. /*************************************************************************/
  122. /* Function: init_structs()                         */
  123. /* Description:                                   */
  124. /*************************************************************************/
  125. init_structs()
  126. {
  127.     arthd =    pagehd = NULLPTR;
  128. }
  129.  
  130.  
  131.  
  132. /*************************************************************************/
  133. /* Function: get_regart()                         */
  134. /* Description:                                 */
  135. /*************************************************************************/
  136. ARTICLE *get_regart(rptr)
  137. REGION *rptr;
  138. {
  139.     return rptr->artptr;
  140. }
  141.  
  142.  
  143.  
  144. /*************************************************************************/
  145. /* Function: open_article()                         */
  146. /* Description:                                 */
  147. /*************************************************************************/
  148. open_article(aptr)
  149. ARTICLE *aptr;
  150. {
  151.     curart = aptr;
  152. }
  153.  
  154.  
  155.  
  156. /*************************************************************************/
  157. /* Function: create_article()                         */
  158. /* Description: Add an article to the article list             */
  159. /*************************************************************************/
  160. create_article()
  161. {
  162.     ARTICLE *newart;
  163.  
  164.         newart = (ARTICLE *)get_lcmem((long)sizeof(ARTICLE));
  165.     newart->nextart = NULLPTR;
  166.       if(arthd == NULLPTR)
  167.     {
  168.         arthd = newart;
  169.     }
  170.     else
  171.     {
  172.            artptr = arthd;
  173.  
  174.         while(artptr->nextart != NULLPTR)
  175.             artptr = artptr->nextart;
  176.         artptr->nextart = newart;
  177.     }
  178.     curart = newart;
  179. }
  180.  
  181.  
  182.  
  183.  
  184. /*************************************************************************/
  185. /* Function: add_to_article()                         */
  186. /* Description:    Add a region to the article list             */
  187. /*************************************************************************/
  188. add_to_article(rptr)
  189. register REGION *rptr;
  190. {
  191.     register REGION *regionptr;
  192.  
  193.     rptr->artptr = curart;
  194.     regionptr = curart->regptr;
  195.     if(regionptr == NULLPTR)
  196.     {
  197.        curart->regptr = rptr;
  198.     }
  199.     else
  200.     {    
  201.        while(regionptr->alink != NULLPTR)
  202.        {
  203.         if(regionptr == rptr)
  204.             return;
  205.         regionptr = regionptr->alink;
  206.        }
  207.        regionptr->alink    = rptr;
  208.     }
  209. }
  210.  
  211.  
  212.  
  213. /*************************************************************************/
  214. /* Function: insert_to_article(()                     */
  215. /* Description: Insert the region into the given article after         */
  216. /* the given region                               */
  217. /*************************************************************************/
  218. insert_to_article(aptr,regptr,rptr)
  219. ARTICLE *aptr;                /* Article to link to            */
  220. REGION *regptr;                /* Region to link after          */
  221. register REGION *rptr;            /* The region to link in     */
  222. {
  223.     rptr->artptr = aptr;        
  224.     rptr->alink = regptr->alink;    /* Link in the article         */
  225.     regptr->alink = rptr;
  226.     insert_regptr = rptr;
  227. }
  228.  
  229.  
  230.  
  231. /*************************************************************************/
  232. /* Function: getf_aregion()                         */
  233. /* Description: Get the first region in the article list pointed to      */
  234. /* by curart                                      */
  235. /*************************************************************************/
  236. REGION *getf_aregion(x1,y1,x2,y2,page)
  237. int *x1;
  238. int *y1;
  239. int *x2;
  240. int *y2;
  241. int *page;
  242. {
  243.    if(curart->regptr == NULLPTR)
  244.     return (REGION *)NULLPTR;
  245.    else
  246.    {
  247.     curregion = curart->regptr;
  248.     *x1 = curregion->x1;
  249.     *y1 = curregion->y1;
  250.     *x2 = curregion->x2;
  251.     *y2 = curregion->y2;
  252.     *page = curregion->p;
  253.     return curregion;
  254.    }
  255. }
  256.  
  257.  
  258.  
  259. /*************************************************************************/
  260. /* Function: getn_aregion()                         */
  261. /* Description:    Return the next article int curarts article list     */
  262. /*************************************************************************/
  263. REGION     *getn_aregion(x1,y1,x2,y2,page)
  264. int *x1;
  265. int *y1;
  266. int *x2;
  267. int *y2;
  268. int *page;
  269. {
  270.    if(curregion->alink == NULLPTR)
  271.           return (REGION *)NULLPTR;
  272.    else
  273.    {
  274.           curregion = curregion->alink;
  275.     *x1 = curregion->x1;
  276.     *y1 = curregion->y1;
  277.     *x2 = curregion->x2;
  278.     *y2 = curregion->y2;
  279.     *page = curregion->p;
  280.          return curregion;
  281.    }
  282. }
  283.  
  284.  
  285. /*************************************************************************/
  286. /* Function: get_arttxt()                         */
  287. /* Description:    Return the text pointer for the current article         */
  288. /*************************************************************************/
  289. char *get_arttxt()
  290. {
  291.    return(curart->buf_start);
  292. }
  293.  
  294.  
  295.  
  296. /*************************************************************************/
  297. /* Function: get_artfname()                         */
  298. /* Description: Return the filename pointer for the current article     */
  299. /*************************************************************************/
  300. char *get_artfname()
  301. {
  302.    return(curart->filename);
  303. }
  304.  
  305.  
  306.  
  307. /*************************************************************************/
  308. /* Function: put_txtptr()                         */
  309. /* Description:    Fill in a regions textptr.                 */
  310. /*************************************************************************/
  311. put_txtptr(rptr,charptr)
  312. REGION  *rptr;
  313. char    *charptr;
  314. {
  315.    rptr->txtstart = charptr;
  316. }
  317.  
  318.  
  319.  
  320. /*************************************************************************/
  321. /* Function: put_grattr()                         */
  322. /* Description:    Fill in a regions graphic attributes             */
  323. /*************************************************************************/
  324. put_grattr(rptr,attr)
  325. register REGION  *rptr;
  326. register int    attr[];
  327. {
  328.    register int i;
  329.  
  330.    for(i = 0;i < NUMGRATTRS;i++)
  331.    {
  332.     rptr->grattr[i] = attr[i];
  333.    }
  334. }
  335.  
  336.  
  337.  
  338. /*************************************************************************/
  339. /* Function: put_txtattr()                         */
  340. /* Description:    Fill in a regions text attributes             */
  341. /*************************************************************************/
  342. put_txtattr(rptr,attr)
  343. REGION  *rptr;
  344. struct txtattr    *attr;
  345. {
  346.    rptr->text = *attr;
  347. }
  348.  
  349.  
  350.  
  351. /************************************************************************/
  352. /* Function: get_txtptr()                            */
  353. /* Description: Return the requested regions text pointer        */
  354. /************************************************************************/
  355. char *get_txtptr(rptr)
  356. REGION  *rptr;
  357. {
  358.    return(rptr->txtstart);
  359. }
  360.  
  361.  
  362.  
  363. /************************************************************************/
  364. /* Function: get_grattr()                        */
  365. /* Description: Return the requested regions graphics attribute list    */
  366. /************************************************************************/
  367. get_grattr(rptr,attr)
  368. register REGION  *rptr;
  369. register int    attr[];
  370. {
  371.    register int i;
  372.  
  373.    for(i = 0;i < NUMGRATTRS;i++)
  374.     attr[i] = rptr->grattr[i];
  375. }
  376.  
  377.  
  378.  
  379. /************************************************************************/
  380. /* Function: get_txtattr()                        */
  381. /* Description: Return the requested regions attribute list        */
  382. /************************************************************************/
  383. get_txtattr(rptr,attr)
  384. REGION  *rptr;
  385. struct txtattr *attr;
  386. {
  387.     *attr = rptr->text;
  388. }
  389.  
  390.  
  391.  
  392. /*************************************************************************/
  393. /* Function: update_article()                         */
  394. /* Description:    Put the given filename and base address into the     */
  395. /* current article                              */
  396. /*************************************************************************/
  397. update_article(fname)
  398. char *fname;
  399. {
  400.     strcpy(&curart->filename[0],fname);
  401.     curart->buf_start = buf_start;
  402.     curart->buf_end   = buf_end;
  403.     curart->free_start = free_start;
  404.     curart->current_char = current_char;
  405. }
  406.  
  407.  
  408.  
  409.  
  410. /*************************************************************************/
  411. /* Function: get_buffvars()                         */
  412. /* Descrition:                                 */
  413. /*    Update the --GLOBAL-- buffer pointers with the ones from the     */
  414. /*    article pointed to by the given region               */
  415. /*************************************************************************/
  416. get_buffvars(rptr)
  417. REGION *rptr;
  418. {
  419.    register ARTICLE *aptr;
  420.  
  421.    aptr = rptr->artptr;
  422.    buf_start = aptr->buf_start;
  423.    buf_end   = aptr->buf_end;
  424.    free_start = aptr->free_start;
  425.    current_char = aptr->current_char;
  426. }
  427.  
  428.  
  429.  
  430. /*************************************************************************/
  431. /* Function: get_abuffvars()                         */
  432. /* Description:                                 */
  433. /*    Update the --GLOBAL-- buffer pointers with the ones from the     */
  434. /*    article pointed to                           */
  435. /*************************************************************************/
  436. get_abuffvars(aptr)
  437. register ARTICLE *aptr;
  438. {
  439.    buf_start = aptr->buf_start;
  440.    buf_end   = aptr->buf_end;
  441.    free_start = aptr->free_start;
  442.    current_char = aptr->current_char;
  443. }
  444.  
  445.  
  446.  
  447. /************************************************************************/
  448. /* Function: put_abuffvars()                            */
  449. /* Description:                                */
  450. /*    Update the articles buffer pointers with the ones in the        */
  451. /*    --GLOBAL-- variables.  Article is found from the given        */
  452. /*    article pointer                            */
  453. /************************************************************************/
  454. put_abuffvars(aptr)
  455. register ARTICLE *aptr;
  456. {
  457.    aptr->buf_start = buf_start;
  458.    aptr->buf_end   = buf_end;
  459.    aptr->free_start = free_start;
  460.    aptr->current_char = current_char;
  461. }
  462.  
  463.  
  464.  
  465. /*************************************************************************/
  466. /* Function: put_buffvars()                         */
  467. /* Description:                                 */
  468. /*************************************************************************/
  469. put_buffvars(rptr)
  470. REGION *rptr;
  471. {
  472.    register ARTICLE *aptr;
  473.  
  474.    aptr = rptr->artptr;
  475.    aptr->buf_start = buf_start;
  476.    aptr->buf_end   = buf_end;
  477.    aptr->free_start = free_start;
  478.    aptr->current_char = current_char;
  479. }
  480.  
  481.  
  482.  
  483.     
  484. /*************************************************************************/
  485. /* Function: add_page()                             */
  486. /* Description:    Add a page to the page list                 */
  487. /*************************************************************************/
  488. add_page(dpage)
  489. int dpage;
  490. {
  491.     register PAGE    *newpage;
  492.         register PAGE   *prev_ptr;
  493.         register PAGE   *curr_ptr;
  494.  
  495.         newpage = (PAGE *)get_lcmem((long)sizeof(PAGE));
  496.  
  497.         if(pagehd == NULLPTR)            /* no pages  */
  498.     {
  499.         pagehd = newpage;
  500.         newpage->nextpage = NULLPTR;
  501.     }
  502.     else
  503.     {
  504.          curr_ptr = prev_ptr = pageptr = pagehd;
  505.        
  506.          if(dpage < pageptr->pagenum)        /* 1 page */
  507.          {
  508.             newpage->nextpage = pagehd;
  509.             pagehd = newpage;
  510.          }
  511.          else
  512.          {
  513.         prev_ptr = pageptr;
  514.         pageptr = pageptr->nextpage;
  515.  
  516.         for(;;)
  517.         {
  518.             if(pageptr == NULLPTR)
  519.                 {
  520.             newpage->nextpage = NULLPTR;
  521.             prev_ptr->nextpage = newpage;
  522.             break;
  523.             }
  524.             else        /* check pagenum in node */
  525.             {
  526.             if(dpage < pageptr->pagenum)
  527.             {
  528.                   newpage->nextpage = pageptr;
  529.                   prev_ptr->nextpage = newpage;
  530.                   break;
  531.             }
  532.             else
  533.             {
  534.                 prev_ptr = pageptr;
  535.                 pageptr = pageptr->nextpage;
  536.             }
  537.             }
  538.             
  539.         }
  540.          }
  541.     }
  542.     newpage->pagenum = dpage;
  543.     newpage->regptr = NULLPTR;
  544.     curpage = newpage;
  545. }
  546.  
  547.  
  548.  
  549. /**************************************************************************/
  550. /* Function: add_region()                          */
  551. /* Description:                                  */
  552. /*    Add a region to the page pointed to by curpage.              */
  553. /*     Make curregion point to this newly created region          */
  554. /**************************************************************************/
  555. add_region(type)
  556. int type;
  557. {
  558.     register REGION    *regionptr;
  559.  
  560.         curregion = (REGION *)get_lcmem((long)sizeof(REGION));
  561.     regionptr = curpage->regptr;
  562.     if(regionptr == NULLPTR)
  563.     {
  564.        curpage->regptr = curregion;
  565.     }
  566.     else
  567.     {    
  568.        while(regionptr->plink != NULLPTR)
  569.         regionptr = regionptr->plink;
  570.        regionptr->plink    = curregion;
  571.     }
  572.     curregion->plink    = NULLPTR;
  573.     curregion->x1       = 0;
  574.     curregion->y1       = 0;
  575.     curregion->x2         = 0;
  576.     curregion->y2        = 0;
  577.     curregion->p        = curpage->pagenum;
  578.     curregion->type        = type;
  579.     curregion->primlist = NULLPTR;
  580.     curregion->artptr   = NULLPTR;
  581.     curregion->alink    = NULLPTR;
  582. }
  583.  
  584.  
  585.  
  586.  
  587. /************************************************************************/
  588. /* Function: valid_page()                        */
  589. /* Description:                                */
  590. /*    Make curpage point to the page structure specified by "dpage"     */
  591. /*     If no such page exists, return 0                */
  592. /************************************************************************/
  593. int valid_page(dpage)
  594. int dpage;
  595. {
  596.    int found;
  597.    register PAGE *pptr;
  598.  
  599.  
  600.    found = FALSE;
  601.    pptr = pagehd;
  602.    if(pptr == NULLPTR)
  603.     return FALSE;
  604.    do
  605.    {
  606.     if(pptr->pagenum == dpage)
  607.         {
  608.        found = TRUE;
  609.        curpage = pptr;
  610.        break;
  611.     }
  612.        pptr = pptr->nextpage;
  613.    }while(pptr != NULLPTR);
  614.    return found;
  615. }
  616.  
  617.  
  618.  
  619. /************************************************************************/
  620. /* Function: ins_page()                             */
  621. /* Description:                             */
  622. /*    Insert a page by bumping the page number of all pages >= to     */
  623. /*    current one.                            */
  624. /************************************************************************/
  625. int ins_page()
  626. {
  627.    register PAGE *pptr;
  628.    register REGION *rptr;
  629.  
  630.    pptr = pagehd;
  631.    if(pptr == NULLPTR)
  632.     return FALSE;
  633.    do
  634.    {
  635.     if(pptr->pagenum >= curr_page)
  636.         {
  637.        pptr->pagenum += 1;
  638.            rptr = pptr->regptr;
  639.        while(rptr)
  640.        {
  641.         rptr->p = pptr->pagenum;
  642.         rptr = rptr->plink;
  643.        }
  644.     }
  645.        pptr = pptr->nextpage;
  646.    }while(pptr != NULLPTR);
  647. }
  648.  
  649.  
  650.  
  651. /**************************************************************************/
  652. /* Function: create_region()                          */
  653. /* Description:                                  */
  654. /*    Create a region on the specified page.  If this page does not       */
  655. /*    exist, create a new one and fill in as many empty pages as needed */
  656. /*     in between.  Make this region the current one pointed to by       */
  657. /*    curregion.                              */
  658. /**************************************************************************/
  659. REGION *create_region(page,type)
  660. int page;
  661. int type;
  662. {
  663.    if(!valid_page(page))
  664.     add_page(page);
  665.    add_region(type);
  666.    return curregion;
  667. }
  668.  
  669.  
  670.  
  671. /**************************************************************************/
  672. /* Function: get_fregion()                          */
  673. /* Description:                                  */
  674. /*    Get the first region on the specified page.  If none exist on the */
  675. /*    page return NULLPTR.                          */
  676. /**************************************************************************/
  677. REGION    *get_fregion(page,x1,y1,x2,y2,type)
  678. int    page;
  679. int    *x1;
  680. int    *x2;
  681. int    *y1;
  682. int     *y2;
  683. int    *type;
  684. {
  685.    if(!valid_page(page))
  686.     return (REGION *)NULLPTR;
  687.    if(curpage->regptr == NULLPTR)
  688.     return (REGION *)NULLPTR;
  689.    else
  690.    {
  691.     sfregion = curpage->regptr;
  692.     *x1 = sfregion->x1;
  693.     *y1 = sfregion->y1;
  694.     *x2 = sfregion->x2;
  695.     *y2 = sfregion->y2;
  696.     *type = sfregion->type;
  697.     return sfregion;
  698.    }
  699. }
  700.  
  701.  
  702.  
  703. /**************************************************************************/
  704. /* Function: get_nregion()                          */
  705. /* Description:                                  */
  706. /*    Get subsequent regions after the one returned by get_fregion.     */
  707. /*     If no other regions exist, NULLPTR is returned.  Note: A       */
  708. /*     get_fregion must be made sometime before this call.          */
  709. /**************************************************************************/
  710. REGION     *get_nregion(x1,y1,x2,y2,type)
  711. int *x1;
  712. int *y1;
  713. int *x2;
  714. int *y2;
  715. int *type;
  716. {
  717.    if(sfregion->plink == NULLPTR)
  718.           return (REGION *)NULLPTR;
  719.    else
  720.    {
  721.           sfregion = sfregion->plink;
  722.     *x1 = sfregion->x1;
  723.     *y1 = sfregion->y1;
  724.     *x2 = sfregion->x2;
  725.     *y2 = sfregion->y2;
  726.     *type = sfregion->type;
  727.          return sfregion;
  728.    }
  729. }
  730.  
  731.  
  732.  
  733.  
  734. /**************************************************************************/
  735. /* Function: open_region()                          */
  736. /* Description:                                  */
  737. /*     Open a region by simply having curregion point to the requested   */
  738. /*    region.                                  */
  739. /**************************************************************************/
  740. open_region(regptr)
  741. REGION *regptr;
  742. {
  743.    curregion = regptr;
  744. }
  745.  
  746.  
  747.  
  748.  
  749. /**************************************************************************/
  750. /* Function: calc_newbounds()                          */
  751. /* Description:                                  */
  752. /*    Determine the new bounding rectangle that will enclose all of the */
  753. /*    primitives of the current region.  If "first_prim" is true then   */
  754. /*    just insert the new primitives minx,miny,maxx,maxy into           */
  755. /*    curregions appropriate variables.  If false then compare these    */
  756. /*     values to curregions current variables to see whether they need   */
  757. /*    to be replaced or not.                          */
  758. /**************************************************************************/
  759. calc_newbounds(first_prim,op,count)
  760. int first_prim;
  761. int op;
  762. register int count;
  763. {
  764.    register int minx,miny,maxx;
  765.    int maxy;
  766.    register int i;
  767.    
  768.    if(op == DSELLIPSE)
  769.    {
  770.     minx = ptsarray[0] - ptsarray[2];
  771.     maxx = ptsarray[0] + ptsarray[2];
  772.     miny = ptsarray[1] - ptsarray[3];
  773.     maxy = ptsarray[1] + ptsarray[3];
  774.    }
  775.    else if((op == DSPOLY) || (op == DSLINE) || (op == DSRBOX))
  776.    {
  777.     i = 0;
  778.     --count;
  779.     minx = maxx = ptsarray[i++];
  780.     miny = maxy = ptsarray[i++];
  781.     while(count--)
  782.     {
  783.        if(ptsarray[i] > maxx)
  784.         maxx = ptsarray[i];
  785.        if(ptsarray[i] < minx)
  786.         minx = ptsarray[i];
  787.        i++;
  788.        if(ptsarray[i] > maxy)
  789.         maxy = ptsarray[i];
  790.        if(ptsarray[i] < miny)
  791.         miny = ptsarray[i];
  792.        i++;
  793.     }
  794.    }
  795.    else if(op == DSPICTURE)
  796.    {
  797.     minx = ptsarray[0];
  798.         miny = ptsarray[1];
  799.         maxx = ptsarray[2];
  800.     maxy = ptsarray[3];
  801.    }
  802.  
  803.    if(first_prim)                /* First primitive in list */
  804.    {
  805.     curregion->x1 = minx;
  806.     curregion->x2 = maxx;
  807.     curregion->y1 = miny;
  808.     curregion->y2 = maxy;
  809.    }
  810.    else
  811.    {
  812.       if(minx < curregion->x1)
  813.          curregion->x1 = minx;
  814.       if(maxx > curregion->x2)
  815.          curregion->x2 = maxx;
  816.       if(miny < curregion->y1)
  817.          curregion->y1 = miny;
  818.       if(maxy > curregion->y2)
  819.          curregion->y2 = maxy;
  820.    }
  821. }
  822.  
  823.  
  824.  
  825.  
  826. /**************************************************************************/
  827. /* Function: add_prim()                              */
  828. /* Description:                                  */
  829. /*    Called by put_poly and put_ellipse.  Allocates space for a new    */
  830. /*     primitive and links it in to curregions primitive list.  Also     */
  831. /*    allocate an initial points block to store the primitives coords.  */
  832. /**************************************************************************/
  833. add_prim(op,count,wrmode)
  834. int op;
  835. int count;
  836. int wrmode;
  837. {
  838.    int first_prim;
  839.    register PRIMITIVE *primptr;
  840.  
  841.    curprim = (PRIMITIVE *)get_lcmem((long)sizeof(PRIMITIVE));
  842.    primptr = curregion->primlist;
  843.    if(primptr == NULLPTR)
  844.     {
  845.     first_prim = TRUE;
  846.        curregion->primlist = curprim;
  847.     }
  848.    else
  849.    {
  850.     first_prim = FALSE;
  851.     while(primptr->nextprim != NULLPTR)
  852.         primptr = primptr->nextprim;
  853.     primptr->nextprim = curprim;
  854.    }
  855.    curprim->op = op;
  856.    curprim->wrmode = wrmode;
  857.    curprim->numpts = count;
  858.    curblk = (PTSBLK *)get_lcmem((long)sizeof(PTSBLK));
  859.    curprim->blkptr = curblk;
  860.    curblk->nextblk = NULLPTR;
  861.    calc_newbounds(first_prim,op,count);
  862. }
  863.  
  864.  
  865.  
  866.  
  867. /**************************************************************************/
  868. /* Function: put_poly()                              */
  869. /* Description:                                  */
  870. /*    Add a polygon to the current region.  Grab points from the global */
  871. /*    points array and allocate as many points blocks as necessary.      */
  872. /**************************************************************************/
  873. put_poly(op,count,write_mode,type)
  874. int op;
  875. register int count;
  876. int write_mode;
  877. int type;
  878. {
  879.    register int i,j;
  880.  
  881.    add_prim(op,count,write_mode,type);
  882.    i = j = 0;
  883.    count *= 2;
  884.    while(count--)
  885.    {
  886.     curblk->points[i++] = ptsarray[j++];
  887.     if(i >= MAXBLK)
  888.     {
  889.        curblk->nextblk = (PTSBLK *)get_lcmem((long)sizeof(PTSBLK));
  890.        curblk = curblk->nextblk;
  891.           curblk->nextblk = NULLPTR;
  892.        i = 0;
  893.     }
  894.    }
  895. }
  896.  
  897.  
  898.  
  899. /**************************************************************************/
  900. /* Function: put_ellipse()                          */
  901. /* Description:    Put an ellipse into curregions primitive list          */
  902. /**************************************************************************/
  903. put_ellipse(write_mode,type)
  904. int write_mode;
  905. {
  906.    register int i;
  907.  
  908.    add_prim(DSELLIPSE,2,write_mode,type);
  909.    for(i = 0;i < 4;i++)
  910.     curblk->points[i] = ptsarray[i];
  911. }   
  912.  
  913.  
  914.  
  915.  
  916. /**************************************************************************/
  917. /* Function: put_image()                          */
  918. /* Description:                                  */
  919. /*    Put a picture descripter into curregions primitive list          */
  920. /*    Assume the bounding rectangle is stored in the global ptsarray    */
  921. /*    Store the file name and other info using the put_poly call      */
  922. /*    ptsarray[0] = x1;                          */
  923. /*    ptsarray[1] = y1;                          */
  924. /*    ptsarray[2] = x2;                          */
  925. /*    ptsarray[3] = y2;                          */
  926. /*    ptsarray[4] = picture type --- 0 = Neo,1 = img,2 = Meta          */
  927. /*    ptsarray[5]...... = filename                      */
  928. /**************************************************************************/
  929. put_image(fname,pictype)
  930. char *fname;
  931. int  pictype;
  932. {
  933.     register int len;
  934.  
  935.     ptsarray[2] = ptsarray[4];
  936.     ptsarray[3] = ptsarray[5];
  937.     ptsarray[4] = pictype;
  938.     len = strlen(fname);        /* Number of chars          */
  939.     len = (len/2)+4;        /* Number of ints required        */
  940.     strcpy(&ptsarray[5],fname);
  941.     put_poly(2,len,1,1);
  942. }
  943.  
  944.  
  945.     
  946. /**************************************************************************/
  947. /* Function: getpts()                              */
  948. /* Description:                                  */
  949. /*    Get the points stored in the primitive pointed to by curprim and  */
  950. /*    place them into the global ptsarray.                  */
  951. /**************************************************************************/
  952. getpts()
  953. {
  954.    register PTSBLK *curblk;
  955.    register int i,j;
  956.    register int  count;
  957.  
  958.    count = curprim->numpts;
  959.    curblk = curprim->blkptr;
  960.    i = j = 0;
  961.    count *= 2;
  962.    while(count--)
  963.    {
  964.     ptsarray[j++] = curblk->points[i++];
  965.     if(i >= MAXBLK)
  966.     {
  967.        curblk = curblk->nextblk;
  968.        i = 0;
  969.     }
  970.    }
  971. }
  972.  
  973.  
  974.  
  975. /**************************************************************************/
  976. /* Function: get_fprimitive()                          */
  977. /* Description:                                  */
  978. /*    Get the first primitive of the requested region. If no primitives */
  979. /*    exist return a -1 as the opcode.  Fill in the points count and    */
  980. /*    writing mode and return the opcode in d0              */
  981. /**************************************************************************/
  982. int get_fprimitive(rptr,count,wrmode)
  983. REGION *rptr;
  984. int *count;
  985. int *wrmode;
  986. {
  987.  
  988.    if(rptr->primlist == NULLPTR)
  989.    {
  990.        *count = 0;
  991.           return -1;
  992.    }
  993.    else
  994.    {
  995.     curprim = rptr->primlist;
  996.     *count = curprim->numpts;
  997.     *wrmode = curprim->wrmode;
  998.     getpts();
  999.     return curprim->op;
  1000.    }
  1001. }
  1002.  
  1003.  
  1004.  
  1005. /**************************************************************************/
  1006. /* Function: get_nprimitive()                          */
  1007. /* Description:                                  */
  1008. /*     Get subsequent primitives after the one returned by the get_fprim */
  1009. /*    call.                                  */
  1010. /**************************************************************************/
  1011. int get_nprimitive(count,wrmode)
  1012. int *count;
  1013. int *wrmode;
  1014. {
  1015.    if(curprim->nextprim == NULLPTR)
  1016.    {
  1017.     *count = 0;
  1018.     return -1;
  1019.    }
  1020.    else
  1021.    {
  1022.     curprim = curprim->nextprim;
  1023.     *count = curprim->numpts;
  1024.       *wrmode = curprim->wrmode;
  1025.      getpts();
  1026.     return curprim->op;
  1027.    }
  1028. }
  1029.  
  1030.  
  1031.  
  1032. /**************************************************************************/
  1033. /* Function: prev_region()                          */
  1034. /* Description:                                  */
  1035. /*    return the region just previous to the given region.  Return 0L   */
  1036. /*    if no other regions exist.  Assume curpage points to the current  */
  1037. /*    page.                                  */
  1038. /**************************************************************************/
  1039. REGION *prev_region(rptr)
  1040. REGION *rptr;
  1041. {
  1042.    register REGION *tptr;
  1043.  
  1044.    tptr = curpage->regptr;
  1045.    if(tptr == rptr)
  1046.     return NULLPTR;
  1047.    else
  1048.    {
  1049.     while(tptr->plink != rptr)
  1050.        tptr = tptr->plink;
  1051.     return tptr;
  1052.    }
  1053. }
  1054.  
  1055.  
  1056.  
  1057.  
  1058. /**************************************************************************/
  1059. /* Function: find_boundary()                          */
  1060. /* Description: Return the boundary points for the given region pointer      */
  1061. /**************************************************************************/
  1062. find_boundary(rptr,minx,miny,maxx,maxy,type,page)
  1063. register REGION *rptr;
  1064. int *minx;
  1065. int *miny;
  1066. int *maxx;
  1067. int *maxy;
  1068. int *type;
  1069. int *page;
  1070. {
  1071.        *minx = rptr->x1;
  1072.        *miny = rptr->y1;
  1073.        *maxx = rptr->x2;
  1074.        *maxy = rptr->y2;
  1075.        *type = rptr->type;
  1076.        *page = rptr->p;
  1077.        curregion = rptr;
  1078. }
  1079.  
  1080.  
  1081.  
  1082.  
  1083. /**************************************************************************/
  1084. /* Function: find_region()                          */
  1085. /* Description:                                  */
  1086. /*    Return the region whose boundaries enclose the given location.    */
  1087. /*    return the boundary points for the callers use.              */
  1088. /**************************************************************************/
  1089. REGION    *find_region(x,y,p,minx,miny,maxx,maxy,type)
  1090. int x,y;
  1091. int p;
  1092. int *minx;
  1093. int *miny;
  1094. int *maxx;
  1095. int *maxy;
  1096. int *type;
  1097. {
  1098.    int xoffset,yoffset;            /* Offset for 1 pixel of mu's */
  1099.    int xadjust,yadjust;
  1100.    register REGION *rptr;
  1101.    int temp;
  1102.  
  1103.    temp = alt_offset;
  1104.    scrntomu(2,2,&xoffset,&yoffset,1);
  1105.    alt_offset = temp;
  1106.  
  1107.    if(!valid_page(p))
  1108.     return (REGION *)NULLPTR;
  1109.    rptr = curpage->regptr;
  1110.    if(rptr == NULLPTR)
  1111.     return (REGION *)NULLPTR;
  1112.    while(rptr->plink != NULLPTR)   
  1113.    {
  1114.     rptr = rptr->plink;
  1115.    }
  1116.    do
  1117.    {
  1118.         if(rptr->x1 == rptr->x2 || rptr->y1 == rptr->y2)
  1119.     {
  1120.         xadjust = xoffset * 3;
  1121.         yadjust = yoffset * 3;
  1122.         }
  1123.     else
  1124.     {
  1125.         xadjust = xoffset;
  1126.         yadjust = yoffset;
  1127.       }
  1128.         
  1129.     if(x >= (rptr->x1)-xadjust && x <= (rptr->x2)+xadjust &&
  1130.        y >= (rptr->y1)-yadjust && y <= (rptr->y2)+yadjust)
  1131.     {
  1132.        *minx = rptr->x1;
  1133.        *miny = rptr->y1;
  1134.        *maxx = rptr->x2;
  1135.        *maxy = rptr->y2;
  1136.        *type = rptr->type;
  1137.        curregion = rptr;
  1138.        return rptr;
  1139.     }
  1140.      rptr = prev_region(rptr);
  1141.    }while(rptr != NULLPTR);
  1142.    return (REGION *)NULLPTR;
  1143. }
  1144.  
  1145.  
  1146.  
  1147.  
  1148. /*************************************************************************/
  1149. /* Function: find_page()                         */
  1150. /* Description:                                 */
  1151. /*************************************************************************/
  1152. find_page(rptr,page)
  1153. REGION *rptr;
  1154. int *page;
  1155. {
  1156.    if(rptr)
  1157.    {
  1158.       *page = rptr->p;
  1159.       curregion = rptr;
  1160.       return 1;
  1161.    }
  1162.    else
  1163.       return 0;
  1164. }
  1165.  
  1166.  
  1167.  
  1168. /**************************************************************************/
  1169. /* Function: inside_region()                          */
  1170. /* Description:                                  */
  1171. /*    Return the region whose boundaries enclose the given location.    */
  1172. /*    return the boundary points for the callers use.              */
  1173. /**************************************************************************/
  1174. int inside_region(x,y,rptr,minx,miny,maxx,maxy,type,page)
  1175. int x,y;
  1176. register REGION *rptr;
  1177. int *minx;
  1178. int *miny;
  1179. int *maxx;
  1180. int *maxy;
  1181. int *type;
  1182. int *page;
  1183. {
  1184.    int xoffset,yoffset;            /* Offset for 1 pixel of mu's */
  1185.    int temp;
  1186.  
  1187.    temp = alt_offset;
  1188.    scrntomu(2,2,&xoffset,&yoffset,1);
  1189.    alt_offset = temp;
  1190.  
  1191.    if(rptr->x1 == rptr->x2 || rptr->y1 == rptr->y2)
  1192.    {
  1193.         xoffset *= 3;
  1194.         yoffset *= 3;
  1195.    }
  1196.    if(x >= (rptr->x1)-xoffset && x <= (rptr->x2)+xoffset &&
  1197.       y >= (rptr->y1)-yoffset && y <= (rptr->y2)+yoffset)
  1198.       {
  1199.        *minx = rptr->x1;
  1200.        *miny = rptr->y1;
  1201.        *maxx = rptr->x2;
  1202.        *maxy = rptr->y2;
  1203.        *type = rptr->type;
  1204.        *page = rptr->p;
  1205.        curregion = rptr;
  1206.        return 1;
  1207.       }
  1208.       else
  1209.        return 0;
  1210. }
  1211.  
  1212.  
  1213.  
  1214.  
  1215. /**************************************************************************/
  1216. /* Function: prev_prim()                          */
  1217. /* Description:                                  */
  1218. /*    Return the previous primitive in the primitive list.  If there    */
  1219. /*    isn't a previous primitive, return 0L.  Assume that curregion     */
  1220. /*    points to the region that is at the head of the current primitive */
  1221. /*    list.                                  */
  1222. /**************************************************************************/
  1223. PRIMITIVE *prev_prim(pptr)
  1224. register PRIMITIVE *pptr;
  1225. {
  1226.    register PRIMITIVE *tptr;
  1227.  
  1228.    tptr = curregion->primlist;
  1229.    if(tptr == pptr)
  1230.     return NULLPTR;
  1231.    else
  1232.    {
  1233.           while(tptr->nextprim != pptr)
  1234.        tptr = tptr->nextprim;
  1235.     return tptr;
  1236.    }
  1237. }
  1238.  
  1239.  
  1240.  
  1241.  
  1242. /**************************************************************************/
  1243. /* Function: prev_blk()                              */
  1244. /* Description:    Return the previous ptsblk to the one that is given      */
  1245. /**************************************************************************/
  1246. PTSBLK *prev_blk(pptr)
  1247. register PTSBLK *pptr;
  1248. {
  1249.    register PTSBLK *tptr;
  1250.  
  1251.    tptr = curprim->blkptr;
  1252.    if(tptr == pptr)
  1253.     return NULLPTR;
  1254.    else
  1255.    {
  1256.           while(tptr->nextblk != pptr)
  1257.        tptr = tptr->nextblk;
  1258.     return tptr;
  1259.    }
  1260. }
  1261.  
  1262.  
  1263.  
  1264.  
  1265. /**************************************************************************/
  1266. /* Function: del_pts()                              */
  1267. /* Description:    Delete all of the blocks associated with the given pointer*/
  1268. /**************************************************************************/
  1269. del_pts()
  1270. {
  1271.    register PTSBLK *tblk;
  1272.    register PTSBLK *pblk;
  1273.  
  1274.    pblk = tblk = curprim->blkptr;
  1275.    if(tblk == NULLPTR)
  1276.     return;
  1277.    while(tblk != NULLPTR)
  1278.    {
  1279.     tblk = pblk->nextblk;
  1280.     free(pblk);
  1281.     pblk = tblk;
  1282.    }
  1283. }
  1284.  
  1285.  
  1286.  
  1287.  
  1288. /**************************************************************************/
  1289. /* Function: delete_primitive()                          */
  1290. /* Description:                                  */
  1291. /*    Delete the current primitive pointed to by curprim.  Fix up links */
  1292. /*     and do a free on the memory.  Assume that curprim belongs to      */
  1293. /*    the region pointed to by curregion.  Return 0 if there are no     */
  1294. /*     other primitives in this region to delete.              */
  1295. /**************************************************************************/
  1296. delete_primitive()
  1297. {
  1298.    PRIMITIVE *pprim;
  1299.    PRIMITIVE *tmpprim;
  1300.  
  1301.    if(curregion->primlist == NULLPTR)
  1302.     return(FALSE);
  1303.    pprim = prev_prim(curprim);
  1304.    if(pprim == NULLPTR)
  1305.    {
  1306.     curregion->primlist = curprim->nextprim;
  1307.         tmpprim = curprim->nextprim;
  1308.    }
  1309.    else
  1310.    {
  1311.  
  1312.     pprim->nextprim = curprim->nextprim;   
  1313.     tmpprim = pprim;
  1314.    }
  1315.    del_pts();
  1316.    free(curprim);
  1317.    curprim = tmpprim;
  1318.    return(TRUE);
  1319. }
  1320.  
  1321.  
  1322.  
  1323.  
  1324. /**************************************************************************/
  1325. /* Function: delete_region()                          */
  1326. /* Description:                                  */
  1327. /*    Delete the region pointed at by curregion.  Return 0 if there are */
  1328. /*    no regions to delete.  Set curregion to the region right before   */
  1329. /*     the deleted one.  If no other regions exist set it to NULLPTR.    */
  1330. /**************************************************************************/
  1331. delete_region(rptr)
  1332. register REGION *rptr;
  1333. {
  1334.    REGION *pregion;
  1335.    register ARTICLE *artptr;
  1336.    register REGION *tregion;
  1337.    REGION *tmpregion;
  1338.    REGION *tmpcur;
  1339.  
  1340.    if(curpage->regptr == NULLPTR)
  1341.     return(FALSE);
  1342.    pregion = prev_region(rptr);
  1343.    if(pregion == NULLPTR)
  1344.    {
  1345.     curpage->regptr = rptr->plink;
  1346.     tmpregion = rptr->plink;
  1347.    }
  1348.    else
  1349.    {
  1350.     pregion->plink = rptr->plink;
  1351.         tmpregion = pregion;   
  1352.    }
  1353.    artptr = rptr->artptr;            /* Delete from article list */
  1354.    if(artptr != NULLPTR)
  1355.    {
  1356.       tregion = artptr->regptr;
  1357.       if(tregion == rptr)
  1358.      artptr->regptr = tregion->alink;
  1359.       else
  1360.       {
  1361.            while(tregion->alink != rptr)
  1362.            {
  1363.          tregion = tregion->alink;
  1364.         }
  1365.          tregion->alink = rptr->alink;
  1366.       }
  1367.    }
  1368.    tmpcur = curregion;
  1369.    curregion = rptr;
  1370.    curprim = prev_prim(NULLPTR);
  1371.    while(delete_primitive());
  1372.                         /* Get last primitive in    */
  1373.                         /* list (primitive right    */
  1374.                         /* before NULLPTR.        */
  1375.                         /* Delete all prims in the  */
  1376.                         /* list.  Assume curprim is */    
  1377.                         /* updated by delete_prim.  */
  1378.    free_scanrects(rptr);            /* free scanlist structs    */
  1379.    curregion = tmpcur;                /* Restore curregion        */
  1380.    free(rptr);
  1381.    return(TRUE);
  1382. }
  1383.  
  1384.  
  1385.  
  1386. /*************************************************************************/
  1387. /* Function: unlink_region()                         */
  1388. /* Description:                                 */
  1389. /*************************************************************************/
  1390. unlink_region(rptr)
  1391. register REGION *rptr;
  1392. {
  1393.    ARTICLE *artptr;
  1394.    register REGION *tregion;
  1395.  
  1396.    artptr = rptr->artptr;            /* Delete from article list */
  1397.    if(artptr != NULLPTR)
  1398.    {
  1399.       tregion = artptr->regptr;
  1400.       if(tregion == rptr)
  1401.      artptr->regptr = tregion->alink;
  1402.       else
  1403.       {
  1404.            while(tregion->alink != rptr)
  1405.            {
  1406.          tregion = tregion->alink;
  1407.         }
  1408.          tregion->alink = rptr->alink;
  1409.       }
  1410.       rptr->artptr = (ARTICLE *)NULLPTR;
  1411.       rptr->alink = (ARTICLE *)NULLPTR;
  1412.       rptr->txtstart = (char *)0L;
  1413.       free_scanrects(rptr);
  1414.    }
  1415. }
  1416.  
  1417.  
  1418.  
  1419. /****************************************************************************/
  1420. /* Function: get_fpage()                            */
  1421. /* Description: Find the first page in our data structure.            */
  1422. /****************************************************************************/
  1423. PAGE *get_fpage(pagenum)
  1424. int *pagenum;
  1425. {
  1426.    if(pagehd == NULLPTR)
  1427.     return NULLPTR;
  1428.    else       
  1429.    {
  1430.     *pagenum = pagehd->pagenum;
  1431.     curpage = pagehd;
  1432.     return curpage;
  1433.    }
  1434. }
  1435.  
  1436.  
  1437.  
  1438. /****************************************************************************/
  1439. /* Function: get_npage()                            */
  1440. /* Description: Find the subsequent pages in our data structure.        */
  1441. /****************************************************************************/
  1442. PAGE *get_npage(pagenum)
  1443. int *pagenum;
  1444. {
  1445.    if(curpage->nextpage == NULLPTR)
  1446.     return NULLPTR;
  1447.    else
  1448.    {
  1449.     curpage = curpage->nextpage;
  1450.     *pagenum = curpage->pagenum;
  1451.     return curpage;
  1452.    }
  1453. }
  1454.  
  1455.  
  1456.  
  1457.  
  1458. /****************************************************************************/
  1459. /* Function: prev_page()                            */
  1460. /* Description:    Find the page just before the requested one            */
  1461. /****************************************************************************/
  1462. PAGE *prev_page(pptr)
  1463. register PAGE *pptr;
  1464. {
  1465.    register PAGE *tptr;
  1466.  
  1467.    tptr = pagehd;
  1468.    if(tptr == pptr)
  1469.     return NULLPTR;
  1470.    else
  1471.    {
  1472.     while(tptr->nextpage != pptr)
  1473.        tptr = tptr->nextpage;
  1474.     return tptr;
  1475.    }
  1476. }
  1477.  
  1478.  
  1479.  
  1480. /****************************************************************************/
  1481. /* Function: delete_page()                            */
  1482. /* Description:    Delete the page pointed to by curpage.                */
  1483. /****************************************************************************/
  1484. int delete_page()
  1485. {
  1486.    PAGE *ppage;
  1487.    PAGE *tmppage;
  1488.    int tpage;
  1489.    int dummy;
  1490.    register REGION *rptr;
  1491.    register PAGE *pptr;
  1492.  
  1493.    if(pagehd == NULLPTR)
  1494.     return FALSE;
  1495.  
  1496.  
  1497.    pptr = pagehd;        /* all pages AFTER the current one  */
  1498.    do                /* have their page numbers bumped   */
  1499.    {                /* DOWN by 1 due to deletion of page*/
  1500.       if(pptr->pagenum > curr_page)
  1501.       {
  1502.         pptr->pagenum -= 1;
  1503.         rptr = pptr->regptr;
  1504.     while(rptr)
  1505.     {
  1506.      rptr->p = pptr->pagenum;
  1507.      rptr = rptr->plink;
  1508.     }
  1509.       }
  1510.       pptr = pptr->nextpage;
  1511.    }while(pptr != NULLPTR);
  1512.    
  1513.  
  1514.    tpage = curpage->pagenum;
  1515.    rptr = get_fregion(tpage,&dummy,&dummy,&dummy,&dummy,&dummy);
  1516.    if(rptr != NULLPTR)
  1517.    {
  1518.            while(rptr)
  1519.            {
  1520.            delete_region(rptr);
  1521.         rptr = get_nregion(&dummy,&dummy,&dummy,&dummy,&dummy);
  1522.        }
  1523.    }
  1524.  
  1525.    ppage = prev_page(curpage);
  1526.    if(ppage == NULLPTR)
  1527.    {
  1528.     if(curpage->nextpage == NULLPTR)
  1529.        pagehd = NULLPTR;
  1530.     else
  1531.     {
  1532.        pagehd = curpage->nextpage;
  1533.        tmppage = pagehd;
  1534.         }
  1535.    }
  1536.    else
  1537.    {
  1538.     ppage->nextpage = curpage->nextpage;
  1539.     tmppage = ppage;   
  1540.    }
  1541.    free(curpage);
  1542.    curpage = tmppage;
  1543.    return(TRUE);
  1544. }
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550. /****************************************************************************/
  1551. /* Function: getf_article()                            */
  1552. /* Description:    Find the first article in our data structure.            */
  1553. /****************************************************************************/
  1554. ARTICLE *getf_article()
  1555. {
  1556.    if(arthd == NULLPTR)
  1557.     return NULLPTR;
  1558.    else       
  1559.    {
  1560.     curart = arthd;
  1561.     return curart;
  1562.    }
  1563. }
  1564.  
  1565.  
  1566.  
  1567. /****************************************************************************/
  1568. /* Function: getn_article()                            */
  1569. /* Description:    Find the subsequent pages in our data structure.        */
  1570. /****************************************************************************/
  1571. ARTICLE *getn_article()
  1572. {
  1573.    if(curart->nextart == NULLPTR)
  1574.     return NULLPTR;
  1575.    else
  1576.    {
  1577.     curart = curart->nextart;
  1578.     return curart;
  1579.    }
  1580. }
  1581.  
  1582.  
  1583.  
  1584. /**************************************************************************/
  1585. /* Function: prev_aregion()                          */
  1586. /* Description:                                  */
  1587. /*    Return the region just previous to the given region.  Return 0L   */
  1588. /*    if no other regions exist.  Assume curart points to the current   */
  1589. /*    article.    (SEARCH BY ARTICLE LINKS)              */
  1590. /**************************************************************************/
  1591. REGION *prev_aregion(rptr)
  1592. register REGION *rptr;
  1593. {
  1594.    register REGION *tptr;
  1595.    ARTICLE *artptr;
  1596.  
  1597.    artptr = rptr->artptr;
  1598.    if(!artptr)
  1599.     return NULLPTR;
  1600.    tptr = artptr->regptr;
  1601.    if(tptr == rptr)
  1602.     return NULLPTR;
  1603.    else
  1604.    {
  1605.     while(tptr->alink != rptr)
  1606.        tptr = tptr->alink;
  1607.     return tptr;
  1608.    }
  1609. }
  1610.  
  1611.  
  1612.  
  1613.  
  1614. /****************************************************************************/
  1615. /* Function: prev_art()                                */
  1616. /* Description:    Find the article just before requested one            */
  1617. /****************************************************************************/
  1618. ARTICLE *prev_art(aptr)
  1619. register ARTICLE *aptr;
  1620. {
  1621.    register ARTICLE *tptr;
  1622.  
  1623.    tptr = arthd;
  1624.    if(tptr == aptr)
  1625.     return NULLPTR;
  1626.    else
  1627.    {
  1628.     while(tptr->nextart != aptr)
  1629.        tptr = tptr->nextart;
  1630.     return tptr;
  1631.    }
  1632. }
  1633.  
  1634.  
  1635.  
  1636.  
  1637. /****************************************************************************/
  1638. /* Function: delete_article()                            */
  1639. /* Description:    Delete the article pointed to by curart.            */
  1640. /****************************************************************************/
  1641. int delete_article()
  1642. {
  1643.    ARTICLE *prevart;
  1644.    register REGION *rptr;
  1645.    REGION *prev_reg;
  1646.  
  1647.    if(arthd == NULLPTR)
  1648.     return FALSE;
  1649.    prevart = prev_art(curart);
  1650.    if(prevart == NULLPTR)
  1651.    {
  1652.     if(curart->nextart == NULLPTR)
  1653.            arthd = NULLPTR;
  1654.     else
  1655.     {
  1656.        arthd = prevart = curart->nextart;
  1657.     }
  1658.    }
  1659.    else
  1660.    {
  1661.     prevart->nextart = curart->nextart;   
  1662.    }
  1663.  
  1664.  
  1665.    rptr = curart->regptr;
  1666.    if(rptr != NULLPTR)
  1667.    {
  1668.       while(rptr->alink != NULLPTR)   
  1669.       {
  1670.      rptr = rptr->alink;
  1671.       }
  1672.       do
  1673.       {
  1674.        prev_reg = prev_aregion(rptr);
  1675.        rptr->artptr = NULLPTR;    /* Restore region variables */
  1676.        rptr->alink  = NULLPTR;
  1677.        rptr->txtstart = NULLPTR;
  1678.        free_scanrects(rptr);
  1679.        rptr = prev_reg;
  1680.       }while(rptr != NULLPTR);
  1681.    }
  1682.    free(curart->buf_start);
  1683.    free(curart);
  1684.    curart = prevart;
  1685.    return(TRUE);
  1686. }
  1687.  
  1688.  
  1689.  
  1690. /**************************************************************************/
  1691. /* Function: getpagenum()                          */
  1692. /* Description:    Get the page number of the current page              */
  1693. /**************************************************************************/
  1694. getpagenum()
  1695. {
  1696.     if(pagehd == NULLPTR)
  1697.         return 1;
  1698.     return curpage->pagenum;
  1699. }
  1700.  
  1701.  
  1702.  
  1703.  
  1704. /*************************************************************************/
  1705. /* Function: update_primitive()                         */
  1706. /* Description:                              */
  1707. /*************************************************************************/
  1708. update_primitive(op,count,wrmode,first_prim)
  1709. int op;
  1710. register int count;
  1711. int wrmode;
  1712. int first_prim;
  1713. {
  1714.    register int i,j;
  1715.  
  1716.    curprim->op = op;        /* ok, not really needed...     */
  1717.    curprim->numpts = count;     /* would count change? probably */
  1718.    curprim->wrmode = wrmode;    /* probably not change also...  */
  1719.    del_pts();
  1720.  
  1721.    curblk = (PTSBLK *)get_lcmem((long)sizeof(PTSBLK));
  1722.    curprim->blkptr = curblk;
  1723.    curblk->nextblk = NULLPTR;
  1724.    calc_newbounds(first_prim,op,count);   /* first prim is needed */
  1725.  
  1726.    switch(op)            /* update ptsarray info according*/
  1727.    {                /* to the op...             */
  1728.      case DSRBOX:
  1729.      case DSLINE:
  1730.      case DSPOLY:  i = j = 0;
  1731.               count *= 2;
  1732.               while(count--)
  1733.            {
  1734.            curblk->points[i++] = ptsarray[j++];
  1735.              if(i >= MAXBLK)
  1736.              {
  1737.                 curblk->nextblk = (PTSBLK *)get_lcmem((long)sizeof(PTSBLK));
  1738.                    curblk = curblk->nextblk;
  1739.                       curblk->nextblk = NULLPTR;
  1740.                    i = 0;
  1741.              }
  1742.               }
  1743.            break;
  1744.  
  1745.      case DSELLIPSE:    for(i=0;i < 4;i++)
  1746.                curblk->points[i] = ptsarray[i];
  1747.             break;
  1748.  
  1749.      case DSPICTURE:    i = j = 0;
  1750.             count *= 2;
  1751.                    while(count--)
  1752.                 {
  1753.                    curblk->points[i++] = ptsarray[j++];
  1754.                    if(i >= MAXBLK)
  1755.                    {
  1756.                        curblk->nextblk = (PTSBLK *)get_lcmem((long)sizeof(PTSBLK));
  1757.                       curblk = curblk->nextblk;
  1758.                          curblk->nextblk = NULLPTR;
  1759.                       i = 0;
  1760.                }
  1761.                 }
  1762.             break;
  1763.    }
  1764. }
  1765.  
  1766.  
  1767.  
  1768.  
  1769. /*************************************************************************/
  1770. /* Function: gr_intersect()                         */
  1771. /* Description:                                 */
  1772. /*************************************************************************/
  1773. int gr_intersect(repel_mode,repoffset,rptr,rect)
  1774. int repel_mode;
  1775. int repoffset;
  1776. register REGION *rptr;            /* graphic region */
  1777. int rect[];                /* text region area */
  1778. {
  1779.    int hoffset,voffset;
  1780.    int grect[4];
  1781.     
  1782.     grect[0] = rptr->x1;
  1783.     grect[1] = rptr->y1;
  1784.     grect[2] = rptr->x2;
  1785.     grect[3] = rptr->y2;
  1786.     if(rect_intersect(grect,rect))
  1787.     {
  1788.        hoffset = repoffset * 18;        /* cnvrt to mu */
  1789.        voffset = repoffset * 16;
  1790.            if(repel_mode == 1)
  1791.        {
  1792.           ptsarray[0] = ptsarray[6] = 0;
  1793.           ptsarray[2] = ptsarray[4] = hpage_size - 1;
  1794.        }
  1795.        else 
  1796.        {
  1797.           ptsarray[0] = ptsarray[6] = rptr->x1 - hoffset;
  1798.           ptsarray[2] = ptsarray[4] = rptr->x2 + hoffset;
  1799.        }
  1800.            ptsarray[1] = ptsarray[3] = rptr->y1 - voffset;
  1801.            ptsarray[5] = ptsarray[7] = rptr->y2 + voffset;
  1802.            return(1);
  1803.     }
  1804.     else
  1805.        return(0);
  1806. }       
  1807.  
  1808.  
  1809.  
  1810.  
  1811. /*************************************************************************/
  1812. /* Function: chk_repel()                         */
  1813. /* Description:                                 */
  1814. /*************************************************************************/
  1815. chk_repel(rptr,rect)
  1816. REGION *rptr;
  1817. int rect[];
  1818. {
  1819.    register REGION *region_ptr;
  1820.    int g_flag;
  1821.    int tmpattr[11];
  1822.    PAGE *tmppage;
  1823.  
  1824.    alerted = 0;                /* No errors yet    */
  1825.    tmppage = curpage;            /* Save off curpage */
  1826.    valid_page(rptr->p);            /* Set curpage to rptr's page */
  1827.    region_ptr = curpage->regptr;    /* Get first region          */
  1828.    curpage = tmppage;            /* restore curpage          */
  1829.    while(region_ptr)
  1830.    {
  1831.        g_flag = region_ptr->type;
  1832.        if(g_flag && !alerted) 
  1833.        {
  1834.            get_grattr(region_ptr,tmpattr);
  1835.        if(tmpattr[4] && gr_intersect(tmpattr[4],tmpattr[5],
  1836.             region_ptr,rect))
  1837.             if(tmpattr[6])            /* repel image */
  1838.            repel_images(region_ptr,region_ptr->x1,region_ptr->y1,
  1839.                                region_ptr->x2,region_ptr->y2,
  1840.                        tmpattr[5],&tmpattr[7]);
  1841.         else
  1842.         {
  1843.            redraw_polygon(4,0,0);       /* repel region */
  1844.           }
  1845.        }
  1846.        region_ptr = region_ptr->plink;
  1847.    }
  1848.    alerted = 0;
  1849. }
  1850.  
  1851.  
  1852.  
  1853.  
  1854. /************************************************************************/
  1855. /* Function: set_repbuff()                        */
  1856. /* Description:    Set graphic regions repel buffer to the given address    */
  1857. /************************************************************************/
  1858. set_repbuff(rptr,addr)
  1859. REGION *rptr;
  1860. long addr;
  1861. {
  1862.     stuffpt(&addr,&rptr->grattr[7]);
  1863. }
  1864.  
  1865.  
  1866.  
  1867.  
  1868. /************************************************************************/
  1869. /* Function: clr_grbuff()                        */
  1870. /* Description:    Clear repel buffer and zero the pointer            */
  1871. /************************************************************************/
  1872. clr_grbuff(rptr)
  1873. register REGION *rptr;
  1874. {
  1875.    long addr;
  1876.  
  1877.    stuffpt(&rptr->grattr[7],&addr);
  1878.    if(addr)
  1879.     free(addr);
  1880.    rptr->grattr[7] = 0;
  1881.    rptr->grattr[8] = 0;
  1882. }
  1883.  
  1884.  
  1885.  
  1886.  
  1887. /*************************************************************************/
  1888. /* Function: get_curreg()                         */
  1889. /* Description:                                 */
  1890. /*************************************************************************/
  1891. REGION *get_curreg(type)
  1892. int *type;
  1893. {
  1894.    if(curregion == (REGION *)NULLPTR)
  1895.    {
  1896.     *type = 0;
  1897.     return(REGION *)NULLPTR;
  1898.    }
  1899.    *type = curregion->type;
  1900.    return curregion;
  1901. }
  1902.  
  1903.  
  1904.  
  1905.  
  1906. /*************************************************************************/
  1907. /* Function: calc_rmem()                         */
  1908. /* Description:                                 */
  1909. /*    Add up memory needed to store structure of the page.         */
  1910. /*    Add 10 to each structure for memory manager pointers whatever    */
  1911. /*    that requirement might be...this should be enough         */
  1912. /*************************************************************************/
  1913. calc_rmem(pageptr,count)
  1914. PAGE *pageptr;
  1915. long *count;
  1916. {
  1917. register REGION *rptr;
  1918. register PRIMITIVE *pptr;
  1919. register PTSBLK *bptr;
  1920.  
  1921.    rptr = pageptr->regptr;
  1922.    if(!rptr)
  1923.     return;
  1924.    while(rptr)
  1925.    {
  1926.        pptr =  rptr->primlist;
  1927.     while(pptr)
  1928.         {
  1929.           bptr = pptr->blkptr;
  1930.        while(bptr)
  1931.            {
  1932.           *count += (long)sizeof(PTSBLK) + 10L;
  1933.           bptr = bptr->nextblk;
  1934.            }    
  1935.        *count += (long)sizeof(PRIMITIVE) + 10L;
  1936.        pptr = pptr->nextprim;
  1937.         }    
  1938.     *count += (long)sizeof(REGION) + 10L;
  1939.     rptr = rptr->plink;
  1940.     }
  1941. }
  1942.  
  1943.  
  1944.  
  1945.  
  1946. /*************************************************************************/
  1947. /* Function: page_to_clip()                         */
  1948. /* Description:                                 */
  1949. /*************************************************************************/
  1950. page_to_clip()
  1951. {
  1952.    REGION *rptr;
  1953.    PRIMITIVE *primptr;
  1954.    register PTSBLK *blkptr;
  1955.  
  1956.    register REGION *crptr;
  1957.    PRIMITIVE *cprimptr;
  1958.    register PTSBLK *cblkptr;
  1959.  
  1960.    REGION *tcurregion;
  1961.    PRIMITIVE *tcurprim;
  1962.  
  1963.    register int i;
  1964.    long memneeded;
  1965.    long memfree;
  1966.  
  1967.    if(!valid_page(curr_page))
  1968.     return(0);
  1969.  
  1970.    memneeded = 0L;
  1971.    calc_rmem(curpage,&memneeded);
  1972.    memfree = Malloc(-1L);
  1973.    if(memfree < memneeded)
  1974.    {
  1975.     alert_cntre(ALERT12);
  1976.     return(0);
  1977.    }      
  1978.    tcurregion = curregion;
  1979.    tcurprim = curprim;
  1980.  
  1981.    clippage = (PAGE *)get_lcmem((long)sizeof(PAGE));
  1982.  
  1983.    rptr = prev_region(NULLPTR);
  1984.    while(rptr)
  1985.    {
  1986.     curregion = rptr;
  1987.         crptr = (REGION *)get_lcmem((long)sizeof(REGION));
  1988.     crptr->plink = clippage->regptr;    
  1989.     clippage->regptr = crptr;
  1990.     crptr->x1 = rptr->x1;
  1991.       crptr->y1 = rptr->y1;
  1992.     crptr->x2 = rptr->x2;
  1993.     crptr->y2 = rptr->y2;
  1994.     crptr->text = rptr->text;
  1995.     for(i = 0;i < 11;i++)
  1996.        crptr->grattr[i] = rptr->grattr[i];
  1997.     crptr->type = rptr->type;
  1998.     primptr = prev_prim(NULLPTR);
  1999.     while(primptr)
  2000.     {
  2001.        curprim = primptr;
  2002.           cprimptr = (PRIMITIVE *)get_lcmem((long)sizeof(PRIMITIVE));
  2003.        cprimptr->nextprim = crptr->primlist;
  2004.        crptr->primlist = cprimptr;
  2005.        cprimptr->op = primptr->op;
  2006.          cprimptr->wrmode = primptr->wrmode;
  2007.        cprimptr->numpts = primptr->numpts;
  2008.        blkptr = prev_blk(NULLPTR);
  2009.        while(blkptr)
  2010.        {
  2011.         cblkptr = (PTSBLK *)get_lcmem((long)sizeof(PTSBLK));
  2012.         cblkptr->nextblk = cprimptr->blkptr;
  2013.         cprimptr->blkptr = cblkptr;
  2014.         for(i = 0;i < 8;i++)
  2015.            cblkptr->points[i] = blkptr->points[i];
  2016.         blkptr = prev_blk(blkptr);
  2017.          }
  2018.        primptr = prev_prim(primptr);
  2019.       }
  2020.         rptr = prev_region(rptr);
  2021.     }
  2022.     curregion = tcurregion;
  2023.     curprim = tcurprim;
  2024.     return(1);
  2025. }
  2026.  
  2027.  
  2028.  
  2029.  
  2030. /*************************************************************************/
  2031. /* Function: clip_to_page()                         */
  2032. /* Description:                                 */
  2033. /*************************************************************************/
  2034. clip_to_page(page)
  2035. int page;
  2036. {
  2037.    REGION *rptr;
  2038.    PRIMITIVE *primptr;
  2039.    register PTSBLK *blkptr;
  2040.  
  2041.    register REGION *crptr;
  2042.    PRIMITIVE *cprimptr;
  2043.    register PTSBLK *cblkptr;
  2044.  
  2045.    PAGE *tcurpage;
  2046.  
  2047.    register int i;
  2048.    long memneeded;
  2049.    long memfree;
  2050.  
  2051.    memneeded = 0L;
  2052.    calc_rmem(clippage,&memneeded);
  2053.    memfree = Malloc(-1L);
  2054.    if(memfree < memneeded)
  2055.    {
  2056.     alert_cntre(ALERT12);
  2057.     return(0);
  2058.    }      
  2059.  
  2060.    if(!valid_page(page))
  2061.       add_page(page);
  2062.    tcurpage = curpage;
  2063.    curpage = clippage;
  2064.    rptr = prev_region(NULLPTR);
  2065.    while(rptr)
  2066.    {
  2067.     curregion = rptr;
  2068.         crptr = (REGION *)get_lcmem((long)sizeof(REGION));
  2069.     crptr->plink = tcurpage->regptr;    
  2070.     tcurpage->regptr = crptr;
  2071.     crptr->x1 = rptr->x1;
  2072.       crptr->y1 = rptr->y1;
  2073.     crptr->x2 = rptr->x2;
  2074.     crptr->y2 = rptr->y2;
  2075.     crptr->text = rptr->text;
  2076.     crptr->p = page;    
  2077.     for(i = 0;i < 11;i++)
  2078.        crptr->grattr[i] = rptr->grattr[i];
  2079.     crptr->type = rptr->type;
  2080.     primptr = prev_prim(NULLPTR);
  2081.     while(primptr)
  2082.     {
  2083.        curprim = primptr;
  2084.           cprimptr = (PRIMITIVE *)get_lcmem((long)sizeof(PRIMITIVE));
  2085.        cprimptr->nextprim = crptr->primlist;
  2086.        crptr->primlist = cprimptr;
  2087.        cprimptr->op = primptr->op;
  2088.          cprimptr->wrmode = primptr->wrmode;
  2089.        cprimptr->numpts = primptr->numpts;
  2090.        blkptr = prev_blk(NULLPTR);
  2091.        while(blkptr)
  2092.        {
  2093.         cblkptr = (PTSBLK *)get_lcmem((long)sizeof(PTSBLK));
  2094.         cblkptr->nextblk = cprimptr->blkptr;
  2095.         cprimptr->blkptr = cblkptr;
  2096.         for(i = 0;i < 8;i++)
  2097.            cblkptr->points[i] = blkptr->points[i];
  2098.         blkptr = prev_blk(blkptr);
  2099.          }
  2100.        primptr = prev_prim(primptr);
  2101.       }
  2102.         rptr = prev_region(rptr);
  2103.     }
  2104.     curpage = tcurpage;
  2105.     curregion = curpage->regptr;
  2106.     curprim = curregion->primlist;
  2107.     return(1);
  2108. }
  2109.  
  2110.  
  2111.  
  2112.  
  2113. /*************************************************************************/
  2114. /* Function: delete_clip()                         */
  2115. /* Description:                                 */
  2116. /*************************************************************************/
  2117. delete_clip()
  2118. {
  2119.    PAGE *temppage;
  2120.    register REGION *rptr;
  2121.  
  2122.    if(clippage == NULLPTR)
  2123.     return;
  2124.    temppage = curpage;
  2125.    curpage = clippage;
  2126.    rptr = curpage->regptr;
  2127.    while(rptr)
  2128.    {
  2129.       delete_region(rptr);
  2130.       rptr = curpage->regptr;
  2131.    }
  2132.    free(curpage);
  2133.    curpage = temppage;
  2134.    clippage = NULLPTR;
  2135. }
  2136.  
  2137.  
  2138.  
  2139.  
  2140. /*************************************************************************/
  2141. /* Function: get_cur_prim()                         */
  2142. /* Description:                                 */
  2143. /*************************************************************************/
  2144. int get_cur_prim(count,wrmode,pptr)
  2145. int *count;
  2146. int *wrmode;
  2147. long *pptr;
  2148. {
  2149.    if(curprim == NULLPTR)
  2150.    {
  2151.     *count = 0;
  2152.     *pptr  = curprim;
  2153.     return -1;
  2154.    }
  2155.    else
  2156.    {
  2157.     *count  = curprim->numpts;
  2158.       *wrmode = curprim->wrmode;
  2159.     *pptr   = curprim; 
  2160.      getpts();
  2161.     return curprim->op;
  2162.    }
  2163. }
  2164.  
  2165.  
  2166.  
  2167.  
  2168. /*************************************************************************/
  2169. /* Function: set_cur_prim()                         */
  2170. /* Description:                                 */
  2171. /*************************************************************************/
  2172. set_cur_prim(pptr)
  2173. long pptr;
  2174. {
  2175.     curprim = pptr;
  2176.     getpts();
  2177. }
  2178.  
  2179.  
  2180.  
  2181.  
  2182. /**************************************************************************/
  2183. /* Function: do_reg_front()                          */
  2184. /* Description:                                  */
  2185. /*     Bring the region to the front of the list or send it to the back  */
  2186. /**************************************************************************/
  2187. do_reg_front(rptr)
  2188. register REGION *rptr;
  2189. {
  2190.    register REGION *tptr;
  2191.  
  2192.    if(rptr->plink == (REGION *)NULLPTR)        /* Already at end of list */
  2193.     return;
  2194.    tptr = curpage->regptr;
  2195.    if(tptr == rptr)
  2196.    {
  2197.     curpage->regptr = rptr->plink;        /* remove from head of list */
  2198.    }
  2199.    else
  2200.    {
  2201.       while(tptr->plink != rptr)
  2202.       {
  2203.      tptr = tptr->plink;
  2204.       }
  2205.       tptr->plink = rptr->plink;        /* Remove from list    */
  2206.    }
  2207.    while(tptr->plink != (REGION *)NULLPTR)
  2208.     tptr = tptr->plink;
  2209.    tptr->plink = rptr;
  2210.    rptr->plink = (REGION *)NULLPTR;
  2211. }
  2212.  
  2213.  
  2214.  
  2215.  
  2216. /*************************************************************************/
  2217. /* Function: do_reg_back()                         */
  2218. /* Description:                                 */
  2219. /*************************************************************************/
  2220. do_reg_back(rptr)
  2221. register REGION *rptr;
  2222. {
  2223.    register REGION *tptr;
  2224.  
  2225.    if(curpage->regptr == rptr)        /* Already at stanrt of list */
  2226.     return;
  2227.    tptr = curpage->regptr;
  2228.    while(tptr->plink != rptr)
  2229.    {
  2230.     tptr = tptr->plink;
  2231.    }
  2232.    tptr->plink = rptr->plink;            /* Remove from list    */
  2233.    rptr->plink = curpage->regptr;
  2234.    curpage->regptr = rptr;
  2235. }
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241. /**************************************************************************/
  2242. /* Function: do_prim_front()                          */
  2243. /* Description:                                  */
  2244. /*     Bring the given prim to the front of the list or send it to the   */
  2245. /*    back                                  */
  2246. /**************************************************************************/
  2247. do_prim_front(pptr)
  2248. register PRIMITIVE *pptr;
  2249. {
  2250.    register PRIMITIVE *tptr;
  2251.  
  2252.    if(pptr->nextprim == (PRIMITIVE *)NULLPTR)    /* Already at end of list */
  2253.     return;
  2254.    tptr = curregion->primlist;
  2255.    if(tptr == pptr)
  2256.    {
  2257.     curregion->primlist = pptr->nextprim;    /* remove from head of list */
  2258.    }
  2259.    else
  2260.    {
  2261.       while(tptr->nextprim != pptr)
  2262.       {
  2263.      tptr = tptr->nextprim;
  2264.       }
  2265.       tptr->nextprim = pptr->nextprim;        /* Remove from list    */
  2266.    }
  2267.    while(tptr->nextprim != (PRIMITIVE *)NULLPTR)
  2268.     tptr = tptr->nextprim;
  2269.    tptr->nextprim = pptr;
  2270.    pptr->nextprim = (PRIMITIVE *)NULLPTR;
  2271. }
  2272.  
  2273.  
  2274.  
  2275.  
  2276. /*************************************************************************/
  2277. /* Function: do_prim_back()                         */
  2278. /* Description:                                 */
  2279. /*************************************************************************/
  2280. do_prim_back(pptr)
  2281. register PRIMITIVE *pptr;
  2282. {
  2283.    register PRIMITIVE *tptr;
  2284.  
  2285.    if(curregion->primlist == pptr)    /* Already at start of list */
  2286.     return;
  2287.    tptr = curregion->primlist;
  2288.    while(tptr->nextprim != pptr)
  2289.    {
  2290.     tptr = tptr->nextprim;
  2291.    }
  2292.    tptr->nextprim = pptr->nextprim;        /* Remove from list    */
  2293.    pptr->nextprim = curregion->primlist;
  2294.    curregion->primlist  = pptr;
  2295. }
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301. /**************************************************************************/
  2302. /* Function: put_scaninfo()                          */
  2303. /* Description:                                  */
  2304. /*     Put slave code information into the given scaninfo structure      */
  2305. /**************************************************************************/
  2306. put_scaninfo(sptr,slaveptr)
  2307. SCANINFO *sptr;
  2308. struct slvlist *slaveptr;
  2309. {
  2310.    sptr->slaveptr = slaveptr;
  2311. }
  2312.  
  2313.  
  2314.  
  2315.  
  2316.  
  2317. /**************************************************************************/
  2318. /* Function: add_scaninfo()                          */
  2319. /* Description:                                  */
  2320. /*    Create a scan rect structure and initialize it with the given     */
  2321. /*    data.                                  */
  2322. /**************************************************************************/
  2323. add_scaninfo(rptr,x1,y1,x2,y2,textptr,slaveptr)
  2324. REGION *rptr;
  2325. int x1,y1,x2,y2;
  2326. char *textptr;
  2327. struct slvlist *slaveptr;
  2328. {
  2329.    register SCANINFO *curscan;
  2330.    register SCANINFO *tscan;
  2331.  
  2332.         curscan = (REGION *)get_lcmem((long)sizeof(SCANINFO));
  2333.     tscan = rptr->scanlist;
  2334.     if(tscan == NULLPTR)
  2335.     {
  2336.        rptr->scanlist = curscan;
  2337.     }
  2338.     else
  2339.     {    
  2340.        while(tscan->nextscan != NULLPTR)
  2341.         tscan = tscan->nextscan;
  2342.        tscan->nextscan = curscan;
  2343.     }
  2344.     curscan->x1 = x1;
  2345.     curscan->x2 = x2;
  2346.     curscan->y1 = y1;
  2347.     curscan->y2 = y2;
  2348.     curscan->textptr = textptr;
  2349.     curscan->slaveptr = slaveptr;
  2350.     curscan->nextscan = NULLPTR;
  2351. }
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357. /**************************************************************************/
  2358. /* Function: getf_scaninfo()                          */
  2359. /* Description:                                  */
  2360. /*    Get the first scaninfo struct in the given regions list          */
  2361. /**************************************************************************/
  2362. SCANINFO *getf_scaninfo(rptr,x1,y1,x2,y2,textptr,slaveptr)
  2363. REGION *rptr;
  2364. int *x1;
  2365. int *y1;
  2366. int *x2;
  2367. int *y2;
  2368. long *textptr;
  2369. long *slaveptr;
  2370. {
  2371.  
  2372.    sfscan = rptr->scanlist;
  2373.    if(sfscan == NULLPTR)
  2374.    {
  2375.      *x1 = *y1 = *x2 = *y2 = 0;
  2376.      *textptr = *slaveptr = 0L;    
  2377.      return(NULLPTR);
  2378.    }
  2379.    else
  2380.    {
  2381.      *x1 = sfscan->x1;
  2382.      *y1 = sfscan->y1;
  2383.      *x2 = sfscan->x2;
  2384.      *y2 = sfscan->y2;
  2385.      *textptr = (long)sfscan->textptr;
  2386.      *slaveptr = (long)sfscan->slaveptr;
  2387.      return sfscan;
  2388.    }
  2389. }
  2390.  
  2391.  
  2392.  
  2393.  
  2394. /**************************************************************************/
  2395. /* Function: getn_scaninfo()                          */
  2396. /* Description:                                  */
  2397. /*    Get subsequent scaninfo structs after a getf_scaninfo call      */
  2398. /**************************************************************************/
  2399. SCANINFO *getn_scaninfo(x1,y1,x2,y2,textptr,slaveptr)
  2400. int *x1;
  2401. int *y1;
  2402. int *x2;
  2403. int *y2;
  2404. long *textptr;
  2405. long *slaveptr;
  2406. {
  2407.    if(sfscan->nextscan == NULLPTR)
  2408.    {
  2409.       *x1 = *y1 = *x2 = *y2 = 0;
  2410.       *textptr = *slaveptr = 0L;    
  2411.       return(NULLPTR);
  2412.    }
  2413.    else
  2414.    {
  2415.      sfscan = sfscan->nextscan;
  2416.      *x1 = sfscan->x1;
  2417.      *y1 = sfscan->y1;
  2418.      *x2 = sfscan->x2;
  2419.      *y2 = sfscan->y2;
  2420.      *textptr = (long)sfscan->textptr;
  2421.      *slaveptr = (long)sfscan->slaveptr;
  2422.      return sfscan;
  2423.    }
  2424. }
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430. /**************************************************************************/
  2431. /* Function: free_scanrects()                          */
  2432. /* Description:                                  */
  2433. /*    Delete scan rectangle structures and free slave ptrs          */
  2434. /**************************************************************************/
  2435. free_scanrects(rptr)
  2436. REGION *rptr;
  2437. {
  2438.    SCANINFO *tscan;
  2439.    register SCANINFO *pscan;
  2440.  
  2441.    pscan = tscan = rptr->scanlist;
  2442.    if(tscan == NULLPTR)
  2443.     return;
  2444.    while(tscan != NULLPTR)
  2445.    {
  2446.     tscan = pscan->nextscan;
  2447.     if(pscan->slaveptr)
  2448.           freeslvlist(pscan->slaveptr);      /* Free slave list        */
  2449.     free(pscan);
  2450.     pscan = tscan;
  2451.    }
  2452.    rptr->scanlist = NULLPTR;
  2453.    rptr->txtstart = NULLPTR;
  2454. }
  2455.  
  2456.  
  2457.  
  2458.  
  2459.  
  2460. /**************************************************************************/
  2461. /* Function: free_regslv()                          */
  2462. /* Description:                                  */
  2463. /*    Free slave pointers in the scan rectangle structures          */
  2464. /**************************************************************************/
  2465. free_regslv(rptr)
  2466. REGION *rptr;
  2467. {
  2468.    register SCANINFO *tscan;
  2469.  
  2470.    tscan = rptr->scanlist;
  2471.    while(tscan != NULLPTR)
  2472.    {
  2473.     if(tscan->slaveptr)
  2474.     {
  2475.           freeslvlist(tscan->slaveptr);      /* Free slave list        */
  2476.        tscan->slaveptr = NULLPTR;
  2477.     }
  2478.     tscan = tscan->nextscan; 
  2479.    }
  2480. }
  2481.  
  2482.  
  2483.  
  2484. /*************************************************************************/
  2485. /* Function: calc_multbox()                         */
  2486. /* Description:                                 */
  2487. /*************************************************************************/
  2488. calc_multbox(rect)
  2489. register int rect[];
  2490. {
  2491.    register REGION *rptr;
  2492.    int found;
  2493.    found = 0;
  2494.    rptr = curpage->regptr;
  2495.    while(rptr)
  2496.    {
  2497.     if(rptr->multi_select)
  2498.     {
  2499.        if(!found)
  2500.        {
  2501.         rect[0] = rptr->x1;
  2502.         rect[1] = rptr->y1;
  2503.         rect[2] = rptr->x2;
  2504.         rect[3] = rptr->y2;
  2505.         found = 1;
  2506.        }
  2507.        else
  2508.        {
  2509.         rect[0] = min(rect[0],rptr->x1);
  2510.         rect[1] = min(rect[1],rptr->y1);
  2511.         rect[2] = max(rect[2],rptr->x2);
  2512.         rect[3] = max(rect[3],rptr->y2);
  2513.            }
  2514.     }
  2515.     rptr = rptr->plink;
  2516.    }
  2517.    if(curr_page % 2 && view_size == PADJCNT)
  2518.    {
  2519.     rect[0] += hpage_size;
  2520.     rect[2] += hpage_size;
  2521.    }
  2522. }
  2523.  
  2524.  
  2525.  
  2526.  
  2527. /*************************************************************************/
  2528. /* Function: clr_multi_flags()                         */
  2529. /* Description:                                 */
  2530. /*************************************************************************/   
  2531. clr_multi_flags(page)
  2532. {
  2533.    register REGION *rptr;
  2534.  
  2535.    if(!valid_page(page))
  2536.     return;
  2537.    rptr = curpage->regptr;
  2538.    while(rptr)
  2539.    {
  2540.     rptr->multi_select = 0;
  2541.         rptr = rptr->plink;
  2542.    }
  2543. }
  2544.  
  2545.  
  2546.  
  2547.  
  2548. /*************************************************************************/
  2549. /* Function: mcalc_multbox()                         */
  2550. /* Description:                                 */
  2551. /*************************************************************************/
  2552. mcalc_multbox(rect)
  2553. register int rect[];
  2554. {
  2555.    register REGION *rptr;
  2556.    int found;
  2557.  
  2558.    found = 0;
  2559.    rptr = curpage->regptr;
  2560.    while(rptr)
  2561.    {
  2562.     if(rptr->multi_select)
  2563.     {
  2564.        if(!found)
  2565.        {
  2566.         rect[0] = rptr->x1;
  2567.         rect[1] = rptr->y1;
  2568.         rect[2] = rptr->x2;
  2569.         rect[3] = rptr->y2;
  2570.         found = 1;
  2571.        }
  2572.        else
  2573.        {
  2574.         rect[0] = min(rect[0],rptr->x1);
  2575.         rect[1] = min(rect[1],rptr->y1);
  2576.         rect[2] = max(rect[2],rptr->x2);
  2577.         rect[3] = max(rect[3],rptr->y2);
  2578.            }
  2579.     }
  2580.     rptr = rptr->plink;
  2581.    }
  2582. }
  2583.